package com.example.sentineldemo.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

/**
 * Created with IntelliJ IDEA 2023.
 * Description:
 * User: 故我
 * Date: 2024-02-15
 * Time: 18:00
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/getname")
    public String getName() {
        return "GetName: " + new Random().nextInt(100);
    }

    @SentinelResource("/user/getid")
    @RequestMapping("/getid")
    public String getId(Integer id) throws InterruptedException {
        Thread.sleep(100);  // 重启之后，sentinel是内存级别的数据，会丢失
        return "GetId: " + new Random().nextInt(100) + "  id : " + id;
    }
}
